package com.example.demo.mapper;

import com.example.demo.entity.Follow;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FollowMapper {
    int insertFollow(Follow follow);
    Follow selectFollowById(Long id);

    @Select("SELECT * FROM follow WHERE follower_user_id = #{followerUserId} AND following_user_id = #{followingUserId}")
    Follow selectFollowByUsers(@Param("followerUserId") Long followerUserId, @Param("followingUserId") Long followingUserId);

    @Select("SELECT * FROM follow WHERE follower_user_id = #{userId} ORDER BY following_time DESC")
    List<Follow> selectFollowingByUserId(Long userId);

    @Select("SELECT * FROM follow WHERE following_user_id = #{userId} ORDER BY following_time DESC")
    List<Follow> selectFollowersByUserId(Long userId);

    @Delete("DELETE FROM follow WHERE id = #{id}")
    int deleteFollowById(Long id);

    @Delete("DELETE FROM follow WHERE follower_user_id = #{followerUserId} AND following_user_id = #{followingUserId}")
    int deleteFollowByUsers(@Param("followerUserId") Long followerUserId, @Param("followingUserId") Long followingUserId);

    @Select("SELECT COUNT(*) FROM follow WHERE follower_user_id = #{followerUserId} AND following_user_id = #{followingUserId}")
    int checkFollowExists(@Param("followerUserId") Long followerUserId, @Param("followingUserId") Long followingUserId);
}